package me.jessyan.armscomponent.app.mvp.ui.activity.learn;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.di.component.DaggerMyPlanLogComponent;
import me.jessyan.armscomponent.app.mvp.contract.learn.MyPlanLogContract;
import me.jessyan.armscomponent.app.mvp.presenter.learn.MyPlanLogPresenter;
import me.jessyan.armscomponent.app.mvp.ui.widget.BrokenLineView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description: 我的学习计划-计划日志  116
 * <p>
 * Created by MVPArmsTemplate on 08/27/2021 22:27
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@Route(path = RouterHub.LEARNING_MYPLANLOGACTIVITY)
public class MyPlanLogActivity extends BaseActivity<MyPlanLogPresenter> implements MyPlanLogContract.View {

    @BindView(R.id.toolbar_title)
    TextView titleToolBar;

    private List<BrokenLineView.YValue> yValues = new ArrayList();
    private List<BrokenLineView.LineValue> lineValues = new ArrayList();
    @BindView(R.id.lineview)
    BrokenLineView lineview;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMyPlanLogComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.learning_activity_my_plan_log; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        titleToolBar.setText("学习计划");
        lineview.setMainValue("最近七天学习时长", "6月", "单位:分钟");

        //模拟折线数据
        for (int i = 19; i <= 25; i++) {
            double value = i * 1.3;
            if (i == 19 || i == 20 || i == 22 || i == 24 || i == 25) {
                value = 0;
            }
            if (i == 21) {
                value = 8;
            }
            if (i == 23) {
                value = 168;
            }
            BrokenLineView.LineValue lineValue = new BrokenLineView.LineValue(value, value + "");
            lineValues.add(lineValue);
        }
        for (int i = 19; i <= 25; i++) {
            BrokenLineView.YValue yValue = new BrokenLineView.YValue(i, i + "");
            yValues.add(yValue);
        }
        lineview.setValue(lineValues, yValues);
    }

    @Override
    public void showLoading() {
    }

    @Override
    public void hideLoading() {
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
